﻿define(function (require) {
    var ProjectStatusValue = {
        Ongoing: 1,
        Archived: 2
    };

    $(function () {
        var service = require('ezdesk/utility/service');
        var utility = require('ezdesk/utility/utility.js');

        require('model/Project');
        require('model/ProjectList');

        var ProjectView = require('view/ProjectView');
        var ProjectListView = require('view/ProjectListView');
        var projectsView = new ProjectListView({ model: new ProjectList });


        $.receiveMessage(function (e) {
            var paramKeyRegex = /\w*(?=\:)/g;
            var key = paramKeyRegex.exec(e.data);
            key = key ? key[0] : e.data;

            if (key == 'show') {

                utility.AjaxLoad.AjaxLoadBegin();

                service.GetAllFullProjects(function (projectList) {
                    utility.AjaxLoad.AjaxLoadEnd();

                    var projects = _.select(projectList, function (project) {
                        return project.StatusValue != ProjectStatusValue.Archived;
                    });


                    if (projects.length == 0) {
                        $('.ui-remind').html('没有项目').show();
                    }

                    projectsView.model.reset(projects);
                });
            }

        });

    })
})
